package gui.Teacher;
import javax.swing.*;
import javax.swing.border.TitledBorder;

import System.MainControl;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.SystemColor;
import java.awt.Font;
import java.awt.Color;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.awt.Dimension;



public class TeacherMainMenu extends JPanel implements ActionListener {
	
	/**
	 * 
	 */
	
	/**panel variables*/
	private JTextField txtWelcome;
	private JButton btnremoveExam;
	private JButton btnAdddExam;
	private JButton btnremoveQ;
	private JButton btnAdddQ;
	private JButton btnExamControl;
	private static final long serialVersionUID = 9149943359753076229L;
	private JPanel FirstPanel = null; 
	public EnableExamGui Eenab;
	public TerminateExam Etermin;
	public ChangeTimeGui Echange;
	public AddExamGui Eadd;
	public RemoveExamGui Erem;
	public AddQuestionGui Qadd;
	public RemoveQuestionGui Qremove;
	public StatisticsGui Stat;
	private JTextField textField;
	private JButton btnLogout;
	private JButton btnNewButton;

	public TeacherMainMenu() {

		    this.setSize(500, 500);
			setBorder(new TitledBorder(null, "Teacher Main Menu", TitledBorder.LEADING, TitledBorder.TOP, null, null));
			setBackground(SystemColor.activeCaption);
			setBounds(100, 100, 622, 350);
			setLayout(null);

			add(getremoveExam());
			add(gettextWelcome());
			add(getAddExam());
			add(getremoveQuestion());
			add(getAddQuestion());
			add(getBtnLogout());
			
			btnNewButton = new JButton("Statistic Review");
			btnNewButton.setFont(new Font("Microsoft New Tai Lue", Font.BOLD, 12));
			btnNewButton.setBounds(98, 266, 141, 40);
			btnNewButton.addActionListener(this);
			add(btnNewButton);
			
			btnExamControl = new JButton("Exam Control");
			btnExamControl.setFont(new Font("Microsoft New Tai Lue", Font.BOLD, 12));
			btnExamControl.addActionListener(this);
			btnExamControl.setBounds(253, 62, 116, 40);
			add(btnExamControl);
		}
	
	private JTextField gettextWelcome()
	{
		if (txtWelcome == null)
		{
			DateFormat dateFormat = new SimpleDateFormat("EEE, MMM d, ''yy",Locale.US);
			Date date = new Date();
			txtWelcome = new JTextField();
			txtWelcome.setEditable(false);
			txtWelcome.setFont(new Font("Tahoma", Font.BOLD, 12));
			txtWelcome.setText("| Welcome "+ MainControl.currentUser.getFirstName() + " | -- | Date: " + dateFormat.format(date) + " |");
			txtWelcome.setBackground(new Color(100, 149, 237));
			txtWelcome.setBounds(98, 23, 330, 28);
		}
		return txtWelcome;
	}
	private JButton getremoveExam()
	{
		if(btnremoveExam == null)
		{
			btnremoveExam = new JButton("<html>Remove Exam</html>");
			btnremoveExam.setForeground(SystemColor.desktop);
			btnremoveExam.setIcon(MainControl.IconAssReview);
			btnremoveExam.setFont(MainControl.MainPanelFont);
			btnremoveExam.setBounds(98, 215, 141, 40);
			btnremoveExam.addActionListener(this);
		}
		return btnremoveExam;
	}
	
	private JButton getAddExam()
	{
		if(btnAdddExam == null)
		{
			btnAdddExam = new JButton("<html>Add Exam</html>");
			btnAdddExam.setForeground(SystemColor.desktop);
			btnAdddExam.setIcon(MainControl.IconAssReview);
			btnAdddExam.setFont(MainControl.MainPanelFont);
			btnAdddExam.setBounds(98, 164, 141, 40);
			btnAdddExam.addActionListener(this);
		}
		return btnAdddExam;
	}

	private JButton getremoveQuestion()
	{
		if(btnremoveQ == null)
		{
			btnremoveQ = new JButton("<html>Remove Question</html>");
			btnremoveQ.setForeground(SystemColor.desktop);
			btnremoveQ.setIcon(MainControl.IconAssReview);
			btnremoveQ.setFont(MainControl.MainPanelFont);
			btnremoveQ.setBounds(98, 62, 141, 40);
			btnremoveQ.addActionListener(this);
		}
		return btnremoveQ;
	}
	
	private JButton getAddQuestion()
	{
		if(btnAdddQ == null)
		{
			btnAdddQ = new JButton("<html>Add Question</html>");
			btnAdddQ.setForeground(SystemColor.desktop);
			btnAdddQ.setIcon(MainControl.IconAssReview);
			btnAdddQ.setFont(MainControl.MainPanelFont);
			btnAdddQ.setBounds(98, 113, 141, 40);
			btnAdddQ.addActionListener(this);
		}
		return btnAdddQ;
	}

	private JButton getBtnLogout() {
		if (btnLogout == null) {
			btnLogout = new JButton("LogOut");
			btnLogout.addActionListener(this);
			btnLogout.setFont(new Font("Microsoft PhagsPa", Font.BOLD, 14));
			btnLogout.setBounds(488, 227, 89, 23);
		}
		return btnLogout;
	}

	
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource()==btnremoveExam)
			MainControl.setTeacherWindows(2);
		if(e.getSource()==btnAdddQ)
			MainControl.setTeacherWindows(3);
		if(e.getSource()==btnAdddExam)
			MainControl.setTeacherWindows(1);
		if(e.getSource()==btnNewButton)
			MainControl.setTeacherWindows(5);
		if(e.getSource()==btnremoveQ)
			MainControl.setTeacherWindows(4);
		if(e.getSource()==btnExamControl)
			MainControl.setTeacherWindows(6);
			//MainControl.setTeacherWindows(6);
		if (e.getSource() == btnLogout)
			{
				MainControl.LogOut(this);
			}
	}
}
   
